<?php

class adminlog extends main {
    function __construct(){
        parent::__construct();
        $this->loadModel('g5_admin_log');
    }

    function index($string = '', $page = 1){
        $string = isset($_GET[2]) ? $_GET[2] : '';
        $page   = isset($_GET[3]) ? max(1, $_GET[3]) : 1;
        $pageSize = 15;
        $where    = $like = array();
        $search = isset($_POST['s']) ? $_POST['s'] : array();
        if( $string !== ''){
            $search = unserialize(base64_decode($string));
        }
        if( ! empty($search['user_truename'])){
            $where['user_true_name'] = trim($search['user_truename']);
        }
        if( ! empty($search['start_time'])){
            $where['time>='] = strtotime(trim($search['start_time']));
        }
        if( ! empty($search['end_time'])){
            $where['time<='] = strtotime(trim($search['end_time']));
        }
        if( ! empty($search['description'])){
            $like['description'] = $search['description'];
        }
        if( ! empty($search['query_uri'])){
            $like['query_uri'] = trim($search['query_uri']);
        }
        $this->search = $search;
        $this->adminlogs = $this->g5_admin_log->like($like)->limit($pageSize,($page-1)*$pageSize)
            ->getAll('id,user_id,user_true_name,query_uri,description,client_ip,time', $where);
        $total             = $this->g5_admin_log->like($like)->getCount('*', $where);
        $params = base64_encode(serialize($search));
        $this->page($page, $total, $params, $pageSize);
        $this->formAction = BASEURI.'adminlog/index';
        $this->adminlog($this->systemLang['watchLoglist']);
    }

    function delete(){
        $ids = isset($_GET[2]) ? array($_GET[2]) : $_POST['select_id'];
        if($this->g5_admin_log->in(array('id'=>$ids))->delete()){
            $this->adminlog($this->systemLang['delOperateLog'].implode(',', $ids));
            $this->report(true, BASEURI.'adminlog/index');
        }else{
            $this->report(false, BASEURI.'adminlog/index');
        }
    }
}